<template>
  <div class="app-container">
    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane label="应用详情" name="info">
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <span>基本信息</span>
          </div>
          <el-descriptions>
            <el-descriptions-item label="应用编码">{{appInfo.appCode}}</el-descriptions-item>
            <el-descriptions-item label="应用简称">{{appInfo.appShort}}</el-descriptions-item>
            <el-descriptions-item label="应用名称">{{appInfo.name}}</el-descriptions-item>
            <el-descriptions-item label="最新版本">{{appInfo.latestSn}}</el-descriptions-item>
            <el-descriptions-item label="缩率图">
              <el-carousel height="100px">
                <el-carousel-item v-for="item in (appInfo.thumbnail || '').split(',')" :key="item">
                  <img  :src="item" class="image" style="width:80px;height:80px;border:none;">
                </el-carousel-item>
              </el-carousel>
            </el-descriptions-item>
            <el-descriptions-item label="商标">
              <img v-if="appInfo.logo" style="width:80px;height:80px;border:none;" :src="appInfo.logo">
            </el-descriptions-item>
            <el-descriptions-item label="售价">{{appInfo.price}}</el-descriptions-item>
            <el-descriptions-item label="安装数量">{{appInfo.install}}</el-descriptions-item>
            <el-descriptions-item label="付费安装">{{appInfo.paidInstall}}</el-descriptions-item>
            <el-descriptions-item label="适用平台">
              <el-tag style="margin-left: 5px" size="small" v-for="i in appInfo.platform" :key="i">{{getDictDataLabel(DICT_TYPE.APP_MARKT_PLATFORM, i ) }}</el-tag>
            </el-descriptions-item>
            <el-descriptions-item label="浏览量">{{appInfo.browse}}</el-descriptions-item>
            <el-descriptions-item label="是否加密">{{getDictDataLabel(DICT_TYPE.SYS_WHETHER_TYPE, appInfo.encrypt)}}</el-descriptions-item>
            <el-descriptions-item label="浏览量">{{appInfo.browse}}</el-descriptions-item>
          </el-descriptions>
        </el-card>
      </el-tab-pane>
      <el-tab-pane label="更新记录" name="record">
        <!-- 列表 -->
        <el-table v-loading="loading" :data="list">
          <el-table-column label="主键" align="center" prop="id" v-if="show"/>
          <el-table-column label="租户ID" align="center" prop="lesseeId" v-if="show"/>
          <el-table-column label="应用ID" align="center" prop="appId" v-if="show"/>
          <el-table-column label="应用简称" align="center" prop="appShort" />
          <el-table-column label="内容" align="center" prop="content" />
          <el-table-column label="分类" align="center" prop="type" />
          <el-table-column label="版本号" align="center" prop="sn" />
          <el-table-column label="下载地址" align="center" prop="appShort" >
            <template slot-scope="scope">
              <a target="_blank"
                 :href="scope.row.downloadUrl"
                 class="text-decoration-none" style="color:blue;cursor:pointer">立即下载</a>
            </template>
          </el-table-column>
          <el-table-column label="兼容范围" align="center" prop="scope" />
          <el-table-column label="应用秘钥" align="center" prop="secret" />
          <el-table-column label="状态" align="center" prop="status" :formatter="statusFormat"/>
          <el-table-column label="创建时间" align="center" prop="createTime" width="180">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.createTime) }}</span>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                         v-hasPermi="['mszf:mg-app-update:update']">修改</el-button>
              <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                         v-hasPermi="['mszf:mg-app-update:delete']">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <!-- 分页组件 -->
        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
                    @pagination="getList"/>

        <!-- 对话框(添加 / 修改) -->
        <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>

        </el-dialog>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import { createMgAppUpdate, updateMgAppUpdate, deleteMgAppUpdate, getMgAppUpdate, getMgAppUpdatePage, exportMgAppUpdateExcel } from "@/api/product/update";
import {DICT_TYPE, getDictDataLabel} from "@/utils/dict";
import {getApp} from "@/api/product/market";
import {isNotEmpty} from "@/utils/ruoyi";
import {isShow} from "@/utils/constants";
import {getAccessToken} from "@/utils/auth";
export default {
  name: "info",
  data() {
    return {
      id:'',
      show:isShow,
      activeName: 'info',
      // 总条数
      total: 0,
      // 应用更新记录列表
      list: [],
      dateRangeCreateTime: [],
      // 遮罩层
      loading: true,
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        lesseeId: null,
        appId: null,
        appShort: null,
        content: null,
        type: null,
        sn: null,
        fid: null,
        downloadUrl: null,
        scope: null,
        secret: null,
        status: null,
      },
      // 表单参数
      appInfo: {
        name:'',
        thumbnail:'',
        logo:'',
        platform:[],
        encrypt:'0',
        visible:'0',
        price:'',
        secrecy:'',
        record:{
          id:'',
          content:'',
          fid:'',
          downloadUrl:'',
          sn:'',
        }
      },
    };
  },
  created() {
    if (this.$route.query.id) {
      this.id =  this.$route.query.id;
      this.getInfo();
    }
    this.getList();
  },
  methods: {
    handleClick(tab, event) {
      console.log(tab, event);
    },
    getInfo(){
      getApp(this.id).then(response => {
        debugger
        this.appInfo = response.data;
        this.appInfo.visible = this.appInfo.visible + '';
        this.appInfo.encrypt = this.appInfo.encrypt + '';
      });
    },
    /** 查询列表 */
    getList() {
      this.loading = true;
      // 处理查询参数
      let params = {...this.queryParams};
      this.addBeginAndEndTime(params, this.dateRangeCreateTime, 'createTime');
      // 执行查询
      getMgAppUpdatePage(params).then(response => {
        this.list = response.data.list;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    // 字典状态字典翻译
    statusFormat(row, column) {
      return getDictDataLabel(DICT_TYPE.SYS_COMMON_STATUS, row.status)
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.open = true;
      this.title = "添加应用更新记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      const id = row.id;
      this.$router.push({
        path: '/product/renew',
        query: {
          id: id
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const id = row.id;
      this.$modal.confirm('是否确认删除应用更新记录编号为"' + id + '"的数据项?').then(function() {
        return deleteMgAppUpdate(id);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
  }
}
</script>

<style scoped>

</style>
